package com.itycu.server.service.business;

import java.util.List;
import com.itycu.server.utils.DateUtils;
import com.itycu.server.dto.business.PraProducesDto;
import com.itycu.server.core.AbstractService;
import com.itycu.server.utils.SecurityUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.itycu.server.mapper.business.PraProducesMapper;
import com.itycu.server.domain.business.PraProduces;

/**
 * 生产子表Service业务层处理
 *
 * @author itycu
 * @date 2025-02-25
 */
@Service("praProducesService")
public class PraProducesService extends AbstractService<PraProduces> {
    @Resource
    private PraProducesMapper praProducesMapper;

    /**
     * 查询生产子表列表
     *
     * @param praProduces 生产子表
     * @return 生产子表
     */
    public List<PraProducesDto> list(PraProduces praProduces) {
        praProduces.setOrderByClause("id desc");
        return praProducesMapper.listByCondition(praProduces);
    }

    /**
     * 根据id获取生产子表详细信息
     */
    @Override
    public PraProducesDto findById(Long id) {
        return praProducesMapper.findById(id);
    }

    /**
     * 保存生产子表
     *
     * @param praProduces 生产子表
     * @return 结果
     */
    @Override
    public int save(PraProduces praProduces) {
        int count;
        if (praProduces.getId() == null) {
            praProduces.setCreateTime(DateUtils.getNowDate());
            praProduces.setCreateBy(SecurityUtils.getUserId());
            count = super.save(praProduces);
        } else {
            praProduces.setUpdateTime(DateUtils.getNowDate());
            praProduces.setUpdateBy(SecurityUtils.getUserId());
            count = super.update(praProduces);
        }
        return count;
    }
}
